package com.lzq.course.business.controller.web;

import com.lzq.course.server.dto.ResponseDto;
import com.lzq.course.server.dto.SmsDto;
import com.lzq.course.server.service.MemberService;
import com.lzq.course.server.service.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("webSmsController")
@RequestMapping("/web/sms")
public class SmsController {

    private static final Logger LOG = LoggerFactory.getLogger(SmsController.class);
    public static final String BUSINESS_NAME = "短信验证码";

    @Resource
    private SmsService smsService;
    @Resource
    private MemberService memberService;

    /**
     * 短信验证码
     * @param smsDto
     * @return
     */
    @RequestMapping(value = "/send", method = RequestMethod.POST)
    public ResponseDto send(@RequestBody SmsDto smsDto) {
        LOG.info("发送短信请求开始: {}", smsDto);
        ResponseDto responseDto = new ResponseDto();
        smsService.sendCode(smsDto);
        LOG.info("发送短信请求结束");
        return responseDto;
    }

    /**
     * 获取手机号是否注册
     * @param smsDto
     * @return
     */
    @RequestMapping(value = "/find-mobile/{mobile}", method = RequestMethod.GET)
    public ResponseDto findMobile(@PathVariable String mobile) {
        ResponseDto responseDto = new ResponseDto();
        boolean flage = memberService.findMobile(mobile);
        responseDto.setSuccess(flage);
        return responseDto;
    }
}
